package game;

import game.classes.Player;

import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 * @author Chris
 */
public class Game extends JFrame {

    public static final String GAMENAME = "Pluton Invaders";
    public static final int FWIDTH = 800;
    public static final int FHEIGHT = 600;
    public static final int BWIDTH = 800;
    public static final int BHEIGHT = 450;
    private JPanel main_menu = null;

    public Game(String name) {
        setTitle(GAMENAME);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setResizable(false);
        setUndecorated(true); //Sacarle los bordes, @Lean req.

        // BEGIN centro de pantalla stuff
        java.awt.Dimension screen_size = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screen_size.width - FWIDTH) / 2, (screen_size.height - FHEIGHT) / 2, FWIDTH, FHEIGHT);
        // END centro de pantalla stuff

        setContentPane(getMainMenu());
        setVisible(true);
    }

    public void singleplayer_handler(String player_name) {
        if (player_name != null) {
            Singleplayer sp = new Singleplayer(this, new Player(player_name));
            changeContentPane(sp.getScreen());
            sp.play();
        }
    }

    public void multiplayer_handler(String player_name) {
        if (player_name != null) {
            Multiplayer mp = new Multiplayer(this, new Player(player_name));
            changeContentPane(mp.getScreen());
            mp.setup();
        }
    }

    public void ranking_handler() {
        Ranking ranking = new Ranking();
        changeContentPane(ranking.showRanking(this));
    }

    public void showMainMenu() {
        changeContentPane(getMainMenu());
    }

    public static void main(String args[]) {
        Game newgame = new Game("Pluton Invaders");
    }

    private JPanel getMainMenu() {
        if (main_menu == null) {
            main_menu = new MainMenu(this);
        }
        return main_menu;
    }

    private void changeContentPane(JPanel toshow) {
        getContentPane().setVisible(false);
        setContentPane(toshow);
        getContentPane().setVisible(true);
    }
}
